$(document).ready(function()
{

	$('#delete').click(function()
	{
		if( $("input:checked[name='tcheckbox']").size()==0)
			{
				alert("Please select atleast one task");
				return false;
			}

		response=confirm("Are you sure you want to delete selected project(s)");

		if(!response)
			return false;
		$('input[name="tcheckbox"]').each(function(index)
		{
			if($(this).attr("checked")==true)
			deleteProject($(this).attr("id"));	

		});
		
	})


$('#deleteUser').click(function()
	{
		if( $("input:checked[name='tcheckbox']").size()==0)
			{
				alert("Please select atleast one task");
				return false;
			}

		response=confirm("Are you sure you want to delete selected user(s)");

		if(!response)
			return false;
		$('input[name="tcheckbox"]').each(function(index)
		{
			if($(this).attr("checked")==true)
			deleteUser($(this).attr("id"));	

		});
		
	})

$('#deleteClient').click(function()
	{
		if( $("input:checked[name='tcheckbox']").size()==0)
			{
				alert("Please select atleast one task");
				return false;
			}

		response=confirm("Are you sure you want to delete selected client(s)");

		if(!response)
			return false;
		$('input[name="tcheckbox"]').each(function(index)
		{
			if($(this).attr("checked")==true)
			deleteClient($(this).attr("id"));	

		});
		
	})

$('#editProject').click(function()
	{
		if( $("input:checked[name='tcheckbox']").size()==0)
			{
				alert("Please select atleast one task");
				return false;
			}
		$('input[name="tcheckbox"]').each(function(index)
		{
			if($(this).attr("checked")==true)
			editProjectTable($(this).attr("id"));	

		});
		
	})









});







function projectModules(ob)
{id=ob.id; 

	$.ajax({
url: "page.php",
type: "POST",
data: "getProjectName="+id,
success: function(html){
	
	name=html;
	
	$.ajax({
	url: "admin_page.php",
	type: "POST",
	data: "showModules="+id,
	success: function(html){
	
		$("#tablediv").html(html);
		$("#tasks").html(name);
		$("#addProject").show();
		$("#editProject").show();
		$("#delete").show();
		$("#addUser").hide();
		$("#addClient").hide();
		$("#deleteClient").hide();
		$("#deleteUser").hide();
		
	}
});

}
	});
}


function allprojects()
{
$.ajax({
url: "admin_page.php",
type: "POST",
data: "allprojects=",
success: function(html){
	
	$("#tablediv").html(html);
	$("#tasks").html("PROJECTS");
	$("#addProject").show();
	$("#editProject").show();
	$("#delete").show();
	$("#clientDrop").show();
	$("#addUser").hide();
	$("#addClient").hide();
	$("#deleteClient").hide();
	$("#deleteUser").hide();
	$("#userTypeDrop").hide();
	$("#statusDrop").hide();


}
});
}




function clients()
{
	$.ajax({
url: "admin_page.php",
type: "POST",
data: "clients=",
success: function(html){
	
	$("#tablediv").html(html);
	$("#tasks").html("CLIENTS");
	$("#addClient").show();
	$("#deleteClient").show();
	$("#statusDrop").show();
	$("#addUser").hide();
	$("#addProject").hide();
	$("#editProject").hide();
	$("#delete").hide();
	$("#deleteUser").hide();
	$("#clientDrop").hide();
	$("#desigDrop").hide();
	$("#userTypeDrop").hide();





}
});
}

function users()
{
$.ajax({
url: "admin_page.php",
type: "POST",
data: "users=",
success: function(html){
	
	$("#tablediv").html(html);
	$("#tasks").html("USERS");
	$("#addUser").show();
	$("#deleteUser").show();
	$("#desigDrop").show();
	$("#userTypeDrop").show();
	
	$("#addProject").hide();
	$("#editProject").hide();
	$("#delete").hide();
	$("#addClient").hide();
	$("#deleteClient").hide();
	$("#clientDrop").hide();
	$("#statusDrop").hide();
	
}
});
}

function addproject()
{
	$.ajax({
url: "admin_page.php",
type: "POST",
data: "addproject=",
success: function(html){
	
	$("#tablediv").html(html);
  $("#addProject").hide();
	$("#editProject").hide();
	$("#delete").hide();
	
}
});
	

}
function addNewProject()
{
	
	var projectName= $("#projectName").val();
	var projectDesc= $("#projectDesc").val();
	var projectClient= $("#projectClient").val();
	var projectDeadline= $("#projectDeadline").val();


	data="addNewproject=&projectName="+projectName+"&projectDesc="+projectDesc+"&projectClient="+projectClient+"&projectDeadline="+projectDeadline;

	$.ajax({
url: "admin_page.php",
type: "POST",
data:data,
success: function(html){	
	$("#tablediv").html(html);
  
	$("#projectName").val("");
	$("#projectDesc").val("");
	$("#projectClient").val("");
	$("#projectDeadline").val("");
	$("#addProject").show();
	$("#editProject").show();
	$("#delete").show();

	 
}
	});
}

function addUser()
{
	$.ajax({
url: "admin_page.php",
type: "POST",
data: "addUser=",
success: function(html){
	
	$("#tablediv").html(html);
	$("#addUser").hide();
	$("#deleteUser").hide();
  
	
}
});
}


function addNewMember()
{


var firstname=$("#firstame").val();
var lastname=$("#lastame").val();
var username=$("#userName").val();
var password=$("#password").val();
var email=$("#email").val();
var designation=$("#adddesig").val();
var usertype=$("#addusertype").val();
data="addnewUser=&firstname="+firstname+"&lastname="+lastname+"&username="+username+"&password="+password+"&email="+email+"&designation="+designation+"&usertype="+usertype;
	$.ajax({
url: "admin_page.php",
type: "POST",
data: data,
success: function(html){
	$("#tablediv").html(html);
	$("#addUser").show();
	$("#deleteUser").show();
	

}
	});
  
}


function deleteProject(id)	
{
	$.ajax({
	url: "admin_page.php",
	type: "POST",
	data: "deleteProject="+id,
	success: function(html){
	$("#tablediv").html(html);
		}
	});
	
}

function deleteUser(id)
{
$.ajax({
	url: "admin_page.php",
	type: "POST",
	data: "deleteUser="+id,
	success: function(html){
	$("#tablediv").html(html);
		}
	});
}

function deleteClient(id)
{
	$.ajax({
	url: "admin_page.php",
	type: "POST",
	data: "deleteClient="+id,
	success: function(html){
	$("#tablediv").html(html);
		}
	});
}
function addClient()
{
$.ajax({
	url: "admin_page.php",
	type: "POST",
	data: "addClient=",
	success: function(html){
	$("#tablediv").html(html);
	$("#addClient").hide();
	$("#deleteClient").hide();

		}
	});
}
function addNewClient()
{
name=$("#clientname").val();
address=$("#clientaddress").val();
email=$("#clientemail").val();
number=$("#clientnumber").val();
status=$("#status").val();


data="addNewClient=&name="+name+"&address="+address+"&email="+email+"&number="+number+"&status="+status;

$.ajax({
	url: "admin_page.php",
	type: "POST",
	data: data,
	success: function(html){
	$("#tablediv").html(html);
	$("#addClient").show();
	$("#deleteClient").show();


		}
	});
}
function editProjectTable(id)
{
	$("#addProject").hide();
	$("#editProject").hide();
	$("#delete").hide();
	
$.ajax({
url: "admin_page.php",
type: "POST",
data: "editProjTable="+id,
success: function(html){
	
	$("#tablediv").html(html);
	$("#addUser").hide();
	$("#deleteUser").hide();
  
	
}
});

}

function project(id)
{

$.ajax({
url: "admin_page.php",
type: "POST",
data: "project="+id,
success: function(html){
	
	$("#tablediv").html(html);
	
	
  
	
}
});

}


function search()
{
	
	var search = $("#searchString").val();

	updateProject("task_name","false",search,"","","");

}
function updateProjectTable(id,sort,descc,search,module,status,priority)
{
	
	data="updateProject=&sort="+sort+"&desc="+descc+"&search="+search;
	data=data+getFilterString();

	$.ajax({
	url: "admin_page.php",
	type: "POST",
	data: data,
	success: function(html)
		{
				$("#tablediv").html(html);
		}
	});
}


function getFilterString()
{
	var module = $("#module").val();
	var status = $("#status").val();
	var priority = $("#priority").val();

	if(module=="--MODULES--")
		module="";
	if(status=="--STATUS--")
		status="";
	if(priority=="--PRIORITY--")
		priority="";

	var string="&module="+module+"&status="+status+"&priority="+priority;

	return string;

}

function editProject(id)
{
	
	
	var editProjectName= $("#editProjName").val();
	var editProjectDesc= $("#editProjectDesc").val();
	var editProjectClient= $("#editProjectClient").val();
	var editProjectDeadline= $("#editProjDeadline").val();


data="updateproject=&id="+id+"&editProjectName="+editProjectName+"&editProjectDesc="+editProjectDesc+"&editProjectClient="+editProjectClient+"&editProjectDeadline="+editProjectDeadline;

	$.ajax({
url: "admin_page.php",
type: "POST",
data:data,
success: function(html){	
	
	$("#tablediv").html(html);
  
	$("#editProjName").val("");
	$("#editProjectDesc").val("");
	$("#editProjectClient").val("");
	$("#editProjectDeadline").val("");
	$("#addProject").show();
	$("#editProject").show();
	$("#delete").show();

	 
}
	});
}

function addMemberTable(id)
{
	
	$.ajax({
url: "admin_page.php",
type: "POST",
data:"addMemberTable="+id,
success: function(html){	
	
	$("#tablediv").html(html);

	 
}
	});
}
function addProjectMember(id)
{
	member=$("#projmember").val();
	memberRole=$("#memberRole").val();
	data="addProjectMember=&id="+id+"&member="+member+"&memberRole"+memberRole;


	$.ajax({
url: "admin_page.php",
type: "POST",
data:data,
success: function(html){	
	
	$("#tablediv").html(html);

	 
}
	});
}
function addModuleTable(id)
{

$.ajax({
url: "admin_page.php",
type: "POST",
data:"addModuleTable="+id,
success: function(html){	
	
	$("#tablediv").html(html);

	 
}
	});

}
function addProjectModule(id)
{
	module=$("#newModule").val();
	data="addProjectModule=&id="+id+"&module="+module;


	$.ajax({
url: "admin_page.php",
type: "POST",
data:data,
success: function(html){	
	
	$("#tablediv").html(html);

	 
}
	});
}

function taskTable(id)
{
$.ajax({
url: "admin_page.php",
type: "POST",
data:"taskTable="+id,
success: function(html){	
	
	$("#tablediv").html(html);

	 
}
	});
}